package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CartController {

    @Autowired
    CartService cartService;

    //添加购物车
    @PostMapping("/cart/add")
    public ResultInfo save(@RequestBody Cart cartParam) {
        Cart cart = cartService.save(cartParam);
        return ResultInfo.success(cart);
    }

    //移除购物车
    @PostMapping("/cart/sub")
    public ResultInfo sub(@RequestBody Cart cartSub) {
        Cart cart = cartService.sub(cartSub);
        return ResultInfo.success(cart);
    }

    //查询购物车
    @GetMapping("/cart/list")
    public ResultInfo findList() {
        List<Cart> list = cartService.findList();
        return ResultInfo.success(list);
    }

    //清空购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo cleanList() {
        cartService.cleanList();
        return ResultInfo.success(null);

    }
}
